
import axios from "axios";
import type { InternalAxiosRequestConfig, AxiosResponse } from "axios";

const service = axios.create({
    baseURL: "http://118.178.238.19:3001/admin"
});

// 请求拦截器
// axios.interceptors.request.use();
service.interceptors.request.use((config: InternalAxiosRequestConfig) => {
    // 给headers增加自定义属性token

    // config.headers.token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbm5hbWUiOiJhZG1pbiIsImlhdCI6MTY3NzQ4NDUwMywiZXhwIjoxNjc3NTEzMzAzfQ.pTzpu0vog_Y5e-JphbWrkRLX6D_7tw5MlYSmanFuP4I";
    // return config;

    if (sessionStorage.getItem("token")) {
        config.headers.token = sessionStorage.getItem("token")
    }
    return config;
});

// 响应拦截器
service.interceptors.response.use((res: AxiosResponse) => {
    return res;
});

export default service;